/*
 * name:垃圾帐号开通初始化 RubbishInit
 * author:yanmu.wj@taobao.com
 * date:2011-11-23
 */
KISSY.use('Phone,ImageCheckCode,RequiredMessage,SubmitForm',function(S,Phone,ImageCheckCode,RequiredMessage,SubmitForm){
    KISSY.ready(function(){
        //图片验证码
        var imageCheckCode = ImageCheckCode({
            input:'#J_checkcode_input',
            img:'#J_checkcode',
            getUrl:'http://regcheckcode.taobao.com/auction/checkcode?sessionID=2d9ec3d19e5bb9aded17340499cc244c',
            checkUrl:'',
            trigger:'#J_refresh_checkcode',
            tip:'#J_checkcode_tip'
        }).init();

        //手机号码
        var phone = Phone({
            input:'#J_phone_input',
            tip:'#J_phone_tip',
        }).init();

        //未绑定手机用户开通第一步：登录
        SubmitForm({
            form:'#J_login_form',
            tip:'#J_login_form_tip',
            checkers:[imageCheckCode]
        }).init();

        //未绑定手机用户开通第二步：绑定手机
        SubmitForm({
            form:'#J_phone_form',
            tip:'#J_phone_form_tip',
            checkers:[phone]
        }).init();

        //未绑定手机用户开通第三步：短信上行验证
        RequiredMessage({
            ajaxUrl:S.one('#J_rm_ajaxUrl') && S.one('#J_rm_ajaxUrl').val() || '',
            data:{
                phone:S.one('#J_rm_phone') && S.one('#J_rm_phone').val() || '',
                param:S.one('#J_rm_param') && S.one('#J_rm_param').val() || '',
                _tb_token:S.one('#J_tb_token') && S.one('#J_tb_token').val() || ''
            },
            interval:5000,
            timeout:60*1000*5,
            successCallBack:function(){
                //校验成功跳转
                var redirectUrl = S.one('#J_rm_redirectUrl') && S.one('#J_rm_redirectUrl').val();
                if(redirectUrl) window.location.assign(redirectUrl);
            },
            timeoutCallBack:function(){
                //超时后自动刷新当前页面，获取新的验证短信内容
            }
        }).init();
    });
});
